/**
 * Created by wangshaohua on 2017/3/29.
 */
var sz_BrowserHelper = {
    isWeChat: function () {
        var ua = navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == "micromessenger") {
            return true;
        } else {
            return false;
        }
    },
    isMicroBenefits: function () {
        var ua = navigator.userAgent.toLowerCase();
        if (ua.indexOf("microbenefits") > -1) {
            return true;
        } else {
            return false;
        }
    },
    isOther: function () {
        var appId = sz_RequestHelper.getParameter('appId');
        if (!appId) {
            appId = sz_ConstantsService.getItem('appId');
        } else {
            sz_ConstantsService.setItem('appId', appId);
        }
        if (appId) {
            return true;
        } else {
            return false;
        }
    },
    isATB: function () {
        var platformCode = sz_RequestHelper.getParameter($sz_Constants.REQUEST_PLATFORM_CODE);
        if (!platformCode) {
            platformCode = sz_ConstantsService.getItem($sz_Constants.PLATFORM_CODE);
        } else {
            sz_ConstantsService.setItem($sz_Constants.PLATFORM_CODE, platformCode);
        }
        if (platformCode && platformCode == 'ATB') {
            return true;
        } else {
            return false;
        }
    },
    connectionType: function () {
        var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
        if (connection) {
            var networkState = connection.type;
            var states = {};
            states[Connection.UNKNOWN] = 'Unknown';//未知连接
            states[Connection.ETHERNET] = 'Ethernet';//以太网
            states[Connection.WIFI] = 'WiFi';//wifi
            states[Connection.CELL_2G] = '2G';//2G
            states[Connection.CELL_3G] = '3G';//3G
            states[Connection.CELL_4G] = '4G';//4G
            states[Connection.CELL] = 'Cell generic';//蜂窝网络
            states[Connection.NONE] = 'No network';

            //alert('Connection type: ' + states[networkState]);
            return states[networkState];
        } else {
            return null;
        }
    }
}